//
//  NYLoginManager.m
//  PromotionCode
//
//  Created by uuu9 on 2017/11/16.
//  Copyright © 2017年 My. All rights reserved.
//

#import "NYLoginManager.h"
#import "NYLoginModel.h"
#import "NYSMSVerificationModel.h"
#import "NYMainModel.h"
#import "NYBindListModel.h"
#import "NYRegionListModel.h"

@implementation NYLoginManager


+(void)getVerifyCodeWithPhone:(NSString *)phone andType:(NSString *)type CompletionHandle:(void (^)(NYSMSVerificationModel *model, NSError *error))complete{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:phone forKey:@"phone"];
    [dict setValue:type forKey:@"type"];
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetVerifyCode]
    parameters:dict
completionHandler:^(id responseObj, NSError *error) {
        NYSMSVerificationModel *model = [NYSMSVerificationModel mj_objectWithKeyValues:responseObj];
        if (model.code != 0) {
            error = [self createError:model.msg];
        }
        complete(model,error);
    }];
    
}

+(void)thrLoginWithOpenID:(NSString *)openid andType:(NSString *)type andName:(NSString *)nickName andImg:(NSString *)image andSexe:(NSString *)sex andCity:(NSString *)city CompletionHandle:(void (^)(LoginModel *, NSError *))complete{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:openid forKey:@"unionid"];
    [dict setValue:type forKey:@"type"];
    [dict setValue:nickName forKey:@"nickname"];
    [dict setValue:image forKey:@"head"];
    [dict setValue:sex forKey:@"sex"];
    [dict setValue:city forKey:@"city"];
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kThirdLogin]
    parameters:dict
completionHandler:^(id responseObj, NSError *error) {
        NYLoginModel *model = [NYLoginModel mj_objectWithKeyValues:responseObj];
        if (model.code != 0) {
            error = [self createError:model.msg];
        }
        complete(model.data,error);
    }];
}


+(void)logoutWithUserid:(NSString *)uid andSessionid:(NSString *)sessionid andCompletionHandle:(void (^)(LoginModel *, NSError *))complete{
    
}

+(void)loginWithPhoneNum:(NSString *)phoneNum andPassword:(NSString *)passwd andCompletionHandle:(void (^)(LoginModel *, NSError *))complete{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:phoneNum forKey:@"phone"];
    [dict setValue:passwd forKey:@"upass"];
    
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kPhoneLogin]
    parameters:dict
completionHandler:^(id responseObj, NSError *error) {
        NYLoginModel *model = [NYLoginModel mj_objectWithKeyValues:responseObj];
        if (model.code != 0) {
            error = [self createError:model.msg];
        }
        complete(model.data,error);
    }];
}



+(void)registerAndLoginWithPhoneNum:(NSString *)phoneNum andVerifyCode:(NSString *)code andCompletionHandle:(void (^)(LoginModel *, NSError *))complete{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:phoneNum forKey:@"phone"];
    [dict setValue:code forKey:@"code"];
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kLoginAndRegisterWithPhoneNum]
    parameters:dict
completionHandler:^(id responseObj, NSError *error) {
        NYLoginModel *model = [NYLoginModel mj_objectWithKeyValues:responseObj];
        if (model.code != 0) {
            error = [self createError:model.msg];
        }
        complete(model.data,error);
    }];
    
}

+(void)modifyPwdWithPhoneNum:(NSString *)phoneNum andPassword:(NSString *)passwd andVerifyCode:(NSString *)code andCompletionHandle:(void (^)(NYMainModel *, NSError *))complete{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:phoneNum forKey:@"phone"];
    [dict setValue:passwd forKey:@"upass"];
    [dict setValue:code forKey:@"code"];
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kModifyPassword]
    parameters:dict
completionHandler:^(id responseObj, NSError *error) {
        NYMainModel *model = [NYMainModel mj_objectWithKeyValues:responseObj];
        if (model.code != 0) {
            error = [self createError:model.msg];
        }
        complete(model,error);
    }];
    
}

+(void)resetPhoneWithUserID:(NSString *)userID andSessionID:(NSString *)sessionID andPhone:(NSString *)phone andCode:(NSString *)code andCompletionHandle:(void (^)(NYMainModel *, NSError *))complete{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:phone forKey:@"phone"];
    [dict setValue:userID forKey:@"userid"];
    [dict setValue:sessionID forKey:@"sessionid"];
    [dict setValue:code forKey:@"code"];
    
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kResetPhone]
    parameters:dict
completionHandler:^(id responseObj, NSError *error) {
        NYMainModel *model = [NYMainModel mj_objectWithKeyValues:responseObj];
        if (model.code != 0) {
            error = [self createError:model.msg];
        }
        complete(model,error);
    }];
}

+(void)modifyUserInfoWithUserID:(NSString *)userID andSessionID:(NSString *)sessionID andNickname:(NSString *)name andNewID:(NSString *)newid andCity:(NSString *)city andGender:(NSString *)gender andBirthday:(NSString *)birthday andDesc:(NSString *)desc andImg:(NSString *)imgUrl andCompletionHandle:(void (^)(NYMainModel *, NSError *))complete{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:userID forKey:@"userid"];
    [dict setValue:sessionID forKey:@"sessionid"];
    [dict setValue:name forKey:@"nickname"];
    [dict setValue:newid forKey:@"no"];
    [dict setValue:gender forKey:@"sex"];
    [dict setValue:birthday forKey:@"birthday"];
    [dict setValue:city forKey:@"city"];
    [dict setValue:desc forKey:@"intro"];
    [dict setValue:imgUrl forKey:@"image"];
    
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kModifyUserInfo]
    parameters:dict
completionHandler:^(id responseObj, NSError *error) {
        NYMainModel *model = [NYMainModel mj_objectWithKeyValues:responseObj];
        if (model.code != 0) {
            error = [self createError:model.msg];
        }
        complete(model,error);
    }];
}

+(void)getThr3BindListWithUserID:(NSString *)uid andSessionID:(NSString *)sessionid andCompletionHandle:(void (^)(NYBindListModel *model, NSError *error))complete{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:uid forKey:@"userid"];
    [dict setValue:sessionid forKey:@"sessionid"];
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetThr3BindList]
    parameters:dict
completionHandler:^(id responseObj, NSError *error) {
        NYBindListModel *model = [NYBindListModel mj_objectWithKeyValues:responseObj];
        if (model.code != 0) {
            error = [self createError:model.msg];
        }
        complete(model,error);
    }];
    
}


+(void)bindThr3WithUserID:(NSString *)uid andSessionID:(NSString *)sessionid andUnionid:(NSString *)unionid andType:(NSString *)type andHead:(NSString *)head andNickname:(NSString *)nickname andSex:(NSString *)sex andCity:(NSString *)city andCompletionHandle:(void (^)(NYMainModel *model, NSError *error))complete{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:uid forKey:@"userid"];
    [dict setValue:sessionid forKey:@"sessionid"];
    [dict setValue:unionid forKey:@"unionid"];
    [dict setValue:type forKey:@"type"];
    [dict setValue:head forKey:@"head"];
    [dict setValue:nickname forKey:@"nickname"];
    [dict setValue:sex forKey:@"sex"];
    [dict setValue:city forKey:@"city"];
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kBindThr3]
    parameters:dict
completionHandler:^(id responseObj, NSError *error) {
        NYMainModel *model = [NYMainModel mj_objectWithKeyValues:responseObj];
        if (model.code != 0) {
            error = [self createError:model.msg];
        }
        complete(model,error);
    }];
}

+(void)getRegionListWithUserID:(NSString *)uid andSessionID:(NSString *)sessionid andParentID:(NSString *)parentid andLevel:(NSString *)level andCompletionHandle:(void (^)(NYRegionListModel *model, NSError *error))complete{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:uid forKey:@"userid"];
    [dict setValue:sessionid forKey:@"sessionid"];
    [self POST:[NSString stringWithFormat:@"%@%@?level=%@&parentid=%@",Api_URL,kModifyRegion,level,parentid]
    parameters:dict
completionHandler:^(id responseObj, NSError *error) {
        NYRegionListModel *model = [NYRegionListModel mj_objectWithKeyValues:responseObj];
        if (model.code != 0) {
            error = [self createError:model.msg];
        }
        complete(model,error);
    }];
    
}



@end
